package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Cmf_Product;
import cn.wolfcode.trip.base.domain.Produce_Content;
import cn.wolfcode.trip.base.mapper.Cmf_ProductMapper;
import cn.wolfcode.trip.base.mapper.Produce_ContentMapper;
import cn.wolfcode.trip.base.query.ProductObject;
import cn.wolfcode.trip.base.service.ICmf_ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Cmf_ProductServiceImpl implements ICmf_ProductService{
    @Autowired
    private Cmf_ProductMapper productMapper;
    @Autowired
    private Produce_ContentMapper produce_contents;

    @Override
    public PageInfo selectForList(ProductObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Cmf_Product> list = productMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public Cmf_Product selectByProductId(Long productId) {
        Produce_Content produce_content = produce_contents.selectByProductIds(productId);
        Cmf_Product cmf_product = productMapper.selectByPrimaryKey(productId);
        if(produce_content!=null){
            cmf_product.setContent(produce_content.getContent());
        }
        return cmf_product;
    }
}
